import com.bourre.events.BasicEvent;
import com.bourre.events.EventType;
import wilberforce.events.simpleEventHelper;
import com.bourre.commands.Delegate;

class wilberforce.ui.forms.checkBox extends simpleEventHelper
{
	private var _container:MovieClip
	private var _selected:Boolean;
	
	public static var CHECKBOX_VALUE_CHANGED:EventType=new EventType("onCheckBoxValueChanged");
	
	public function checkBox(container:MovieClip)
	{
		super();
		_selected=false;
		_container=container;
		_container.onPress=Delegate.create(this,toggleSelected);
	}
	
	private function toggleSelected():Void
	{
		_selected=!_selected;
		if (_selected) 
		{
			_container.gotoAndStop(2);
		}
		else _container.gotoAndStop(1);
		dispatchEvent(new BasicEvent(CHECKBOX_VALUE_CHANGED,this));
	}
	
	public function get selected():Boolean
	{
		return _selected;
	}
	
	public function set selected(value:Boolean):Void
	{
		if (value!=_selected) toggleSelected();
	}
}